package com.zh.note.huawei.onehundred.时间格式化;

/**
 * @Author: zhanghuan
 * @date: 2023/8/30 09:13
 * @description: create it
 */

import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        try (Scanner s = new Scanner(System.in)) {
            int n = s.nextInt();
            s.nextLine();
            List<String> times = new ArrayList<>();
            for (int i = 0; i < n; ++i) {
                times.add(s.nextLine());
            }
            times = times.stream().sorted(Comparator.comparingLong(str -> getTime(str))).collect(Collectors.toList());
            times.forEach(System.out::println);
        }
    }

    // 转化成毫秒
    private static long getTime(String str) {
        String[] t = str.split(":|\\.");
        int h = Integer.parseInt(t[0]) * 60 * 60 * 1000;
        int m = Integer.parseInt(t[1]) * 60 * 1000;
        int s = Integer.parseInt(t[2]) * 1000;
        int n = Integer.parseInt(t[3]);
        return h + m + s + n;
    }
}

